package com.ylfstu.date_;

import java.util.Calendar;

public class Calender_ {
    public static void main(String[] args) {
        //1.Calender 是一个抽象类，并且构造器是private
        //2.可以通过 getInstance() 来获取实例
        //3.提供大量的方法和字段提供给程序员
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar);
        //4.获取日历对象的某个日历字段
        System.out.println("年：" + calendar.get(Calendar.YEAR));
        System.out.println("月：" + (calendar.get(Calendar.MONTH) + 1));
        System.out.println("日：" + calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println("小时：" + calendar.get(Calendar.HOUR));
        System.out.println("分钟：" + calendar.get(Calendar.MINUTE));
        System.out.println("秒：" + calendar.get(Calendar.SECOND));

        //5.Calender 没有专门的格式化方法，所以需要程序员自己来组合输出
        System.out.println(calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH) + "-"
                + calendar.get(Calendar.DAY_OF_MONTH) + " " + calendar.get(Calendar.HOUR) + ":"
                + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND));

        //6.如果要输出24小时制时间， Calender.HOUR --> Calender.HOUR_OF_DAY
        System.out.println(calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH) + "-"
                + calendar.get(Calendar.DAY_OF_MONTH) + " " + calendar.get(Calendar.HOUR_OF_DAY) + ":"
                + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND));

    }
}
